﻿using System.Collections.Generic;
using PerceptiveMCAPI;

namespace PerceptiveMCAPI_UI.Controls.get
{
   public partial class get_listInterestGrouping : System.Web.UI.UserControl
   {
      public ApiMethod method { get; set; }

      public bool grouping_id_visible
      {
         get { return liGroupingId.Visible; }
         set { liGroupingId.Visible = value; }
      }
      public bool grouping_add_visible
      {
         get { return liGroupingAdd.Visible; }
         set { liGroupingAdd.Visible = value; }
      }
      public bool grouping_update_visible
      {
         get { return liGroupingUpd.Visible; }
         set { liGroupingUpd.Visible = value; }
      }
      public string listId
      {
         get { return tbInterestListId.Text.Trim(); }
         set { tbInterestListId.Text = value; }
      }
      public int grouping_id
      {
         get
         {
            int it;
            int.TryParse( tbListGroupingId.Text.Trim(), out it );
            return it;
         }
         set { tbListGroupingId.Text = value.ToString(); }
      }
      public string grouping_name
      {
         get { return tbListAddName.Text.Trim(); }
         set { tbListAddName.Text = value; }
      }
      public EnumValues.grouping_type_field grouping_type
      {
         get { return ApiHelper.GetEnumFromString<EnumValues.grouping_type_field>( ddlListAddType.SelectedValue ); }
         set { ddlListAddType.SelectedValue = value.ToString(); }
      }
      public List<string> grouping_groups
      {
         get { return ApiHelper.MakeListFromString( tbListAddGroups.Text.Trim() ); }
         set { tbListAddGroups.Text = ApiHelper.MakeStringFromList( value ); }
      }

      public string grouping_upd_name
      {
         get { return ddlUpdate.SelectedValue; }
         private set { ddlUpdate.SelectedValue = value; }
      }
      public string grouping_upd_value
      {
         get { return tbListUpdValue.Text.Trim(); }
         set { tbListUpdValue.Text = value; }
      }
      // ----------------------------------------------------------
      public void Setup()
      {
         this.Visible = true;
         lblSection.Text = method.section;
         lblMethod.Text = method.name;
         //
         if ( method.name == "listInterestGroupings" )
         {
            grouping_id_visible = false;
            grouping_add_visible = false;
            grouping_update_visible = false;
         }
         else if ( method.name == "listInterestGroupingAdd" )
         {
            grouping_id_visible = false;
            grouping_add_visible = true;
            grouping_update_visible = false;
            //
            ddlListAddType.DataSource = ApiHelper.GetEnumValues<EnumValues.grouping_type_field>();
            ddlListAddType.DataBind();
         }
         else if ( method.name == "listInterestGroupingUpdate" )
         {
            grouping_id_visible = true;
            grouping_add_visible = false;
            grouping_update_visible = true;
         }
         else           //  del
         {
            grouping_id_visible = true;
            grouping_add_visible = false;
            grouping_update_visible = false;
         }
      }
   }
}